package com.everflourish.yeah100.act.questionlib;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

import com.everflourish.yeah100.R;
import com.everflourish.yeah100.act.base.BaseActivity;
import com.everflourish.yeah100.adapter.ImageViewPagerAdapter;
import com.everflourish.yeah100.utils.IntentUtil;

import java.util.ArrayList;

/**
 * 作者：Created by liqisi on 2016/7/19.
 * 时间：2016/7/19
 */
public class QuestionImageActivity extends BaseActivity {

    private ImageViewPagerAdapter adapter;
    private HackyViewPager pager;
    private ArrayList<String> imageList;
    private int imageIndex;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_question_image);
        initData();
        iniView();
    }

    private void initData() {
        imageList = (ArrayList<String>) getIntent().getSerializableExtra(
                IntentUtil.QUESTIONLISTIMAGE);
        imageIndex = getIntent().getIntExtra(IntentUtil.QUESTIONLISTIMAGEINDEX, 0);
    }

    private void iniView() {
        pager = (HackyViewPager) findViewById(R.id.pager);
        pager.setLocked(false);
        adapter = new ImageViewPagerAdapter(getSupportFragmentManager(), imageList, true);
        pager.setAdapter(adapter);
        pager.setCurrentItem(imageIndex);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            closeAct();
            return true;
        } else {
            return super.onKeyUp(keyCode, event);
        }
    }

    public void closeAct() {
        finish();
    }

}
